var list, div, right, div1,cookie,cont2,cont3
import up from '../js/up.js';
init();
up.up();
async function init() {
    var response = await fetch("http://localhost:3860/list")
    var data = await response.json();
    init1(data)
}

function init1(data) {
    list = document.querySelector(".list-foot").querySelector(".right")
    div = list.querySelector("ul")
    right = document.querySelector("#right")
    div1 = right.querySelector("ul")
    cookie=localStorage
    
    for (var i = 0; i < data.length; i++) {
        var goods = createGoods(div, data[i]);
        var good = createGoods(div1, data[i]);
        right.appendChild(goods)
        list.appendChild(good);
    }
    cookieHandler(cookie)
}

function cookieHandler(cookie){
    var cont2=document.querySelector(".cont2")
    var cont3=document.querySelector(".cont3")
   
    if(cookie.bool){
        cont2.style.display="none";
        cont3.style.display="block"
        cont3.innerHTML=`
        <ul>
        <li>
            <span>${cookie.input}</span>
            <img src="https://p3.lefile.cn/product/adminweb/2019/01/22/f1d4b5d5-b229-4bb5-93f4-7f0e64b274fe.png"
                alt="" class="imgs">
        </li>
        <li>
            <a href="../sass/shopping.html">
                <img src="https://p2.lefile.cn/product/adminweb/2019/01/18/9f0e8935-982b-4ca9-8772-28da55bd3c5e.png"
                    alt="" class="img1">
            </a>
        </li>
    </ul>
        `
    }else{
        cont2.style.display="block";
        cont3.style.display="none"
    }
}

function createGoods(div, data) {
    createGoodsContent(div, data)
    return div
}


function createGoodsContent(div, data) {
    div.innerHTML += `
    <li>
        <div class="li-top">
            <a href="../sass/deta.html?pid=${data.pid}">
            <img src="${data.img}" alt="">
        </a>
        </div>
    <div class="li-foot">
        <a href="../sass/deta.html?pid=${data.pid}" class="a1">${data.txt}</a>
        <a href="../sass/deta.html?pid=${data.pid}" class="a2">${data.text}</a>
        <p>
            <a href="../sass/deta.html?pid=${data.pid}">
                <span>￥</span><span>${data.money}</span>
            </a>
        </p>
    </div>
</li>
    `
}